*Analysis Do-File for creating Figure 5
*Runs diff-in-difference (DD) regressions for crime and produces coefficient plots

***File set-up
macro drop _all
mat drop _all
eststo clear
estimates clear
global path "[ENTER PATH HERE]"
global figs "$path\REStat Replication V2\Figures"
global log "$path\REStat Replication V2\Log Files"
set scheme lean2

clear
set more off

cap log close
log using "$log\figure_5.txt", replace text
use "$path\REStat Replication V2\Data\master_data_analysis_subset"

*Set folder for main figures
cd "$figs"


***DD regression: Arrests on timing of the highest-profile police killing per jursidiction
*Creates estimates for Figure 5 and Table E6-7

***Estimates for Violent Crime
local outcome index_violent murder_tot agg_assault_tot robbery_tot
local descrip `""Panel A: Violent Crime" "Panel B: Murder" "Panel C: Aggravated Assault" "Panel D: Robbery"'

*Run loop for each outcome
	*Could also use gettoken (search about "parallel list structure")
forvalues i = 1/4{
	local crime : word `i' of `outcome'
	local panel : word `i' of `descrip'

	
foreach var of varlist `crime' {

	di "Analysis by qtr for extended event window"
	di "Highest profile OF DiD in ori"
	eststo cln_`var'_hi: reghdfe ln_actual_`var' ln_pop_s ///
		treat_post_high neg_window_high pos_window_high ///
		if !inlist(., ln_`var', ln_actual_index_violent, ln_actual_index_property) ///
		, cl(group_ori) absorb(group_ori month_year ///
		)
	mat coef_`var' = r(table)'
	mat coef_`var' = (coef_`var'[rownumb(coef_`var',"treat_post_high"), ///
		colnumb(coef_`var',"b")..colnumb(coef_`var',"se")])			
	
	di "Pre-trend regressions DiD"
	eststo cln_`var'_hip: reghdfe ln_actual_`var' ln_pop_s ///
		treat_post_high pretrend_high neg_window_high pos_window_high ///
		if !inlist(., ln_`var', ln_actual_index_violent, ln_actual_index_property) ///
		, cl(group_ori) absorb(group_ori month_year ///
		)
		
		
	}
}

***Estimates for Property Crime
local outcome index_property mtr_veh_theft_tot burglary_tot theft_tot
local descrip `""Panel A: Property Crime" "Panel B: Motor Vehicle Theft" "Panel C: Burglary" "Panel D: Theft" "'
*Run loop for each outcome
	*Could also use gettoken (search about "parallel list structure")
forvalues i = 1/4{
	local crime : word `i' of `outcome'
	local panel : word `i' of `descrip'

foreach var of varlist `crime' {

	di "Analysis by qtr for extended event window"
	di "Highest profile OF DiD in ori"
	eststo cln_`var'_hi: reghdfe ln_actual_`var' ln_pop_s ///
		treat_post_high neg_window_high pos_window_high ///
		if !inlist(., ln_`var', ln_actual_index_violent, ln_actual_index_property) ///
		, cl(group_ori) absorb(group_ori month_year ///
		)
		
	mat coef_`var' = r(table)'
	mat coef_`var' = (coef_`var'[rownumb(coef_`var',"treat_post_high"), ///
		colnumb(coef_`var',"b")..colnumb(coef_`var',"se")])		
	
	di "Pre-trend regressions DiD"
	eststo cln_`var'_hip: reghdfe ln_actual_`var' ln_pop_s ///
		treat_post_high pretrend_high neg_window_high pos_window_high ///
		if !inlist(., ln_`var', ln_actual_index_violent, ln_actual_index_property) ///
		, cl(group_ori) absorb(group_ori month_year ///
		)
		
	}

}

****Create DD crime coefplot
mat DD_long = coef_murder_tot \ coef_agg_assault_tot \ coef_robbery_tot \ ///
	coef_mtr_veh_theft_tot \ coef_burglary_tot \ coef_theft_tot		
mat colnames DD_long = b se

mat rownames DD_long = "Murder" "Aggravated Assault" "Robbery" ///
	 "Motor Vehicle Theft" "Burglary" "Theft"

coefplot mat(DD_long[,1]), horizontal xline(0, lcolor(red)) se(DD_long[,2])  /// 
	ylabel(, angle(0) glcolor(gs12) nogrid) ///
	xlabel(-0.05(0.05)0.20, glcolor(gs12) grid) grid(none) xsc(r(-0.06)) ///
	msize(large) msymbol(O) mfcolor(black%100) mcolor(white%0) ///
	xtitle(Change in Log Points) ytitle(Crime Category) ///
	headings(Murder = "{bf:Violent Crime}" "Motor Vehicle Theft" = "{bf:Property Crime}")
graph export "$figs/figure_5.pdf", replace


cap log close

